package main

import (
	"fmt"
)

type Channels struct {
	in  chan int
	out chan int
}

func doWork(id int, chs Channels) {
	go func() {
		for {
			fmt.Printf("id=%d,num=%c \n", id, <-chs.in)
			go func() { chs.out <- 1 }()
		}
	}()
}

func createWorker(id int) Channels {
	chs := Channels{
		make(chan int),
		make(chan int),
	}
	doWork(id, chs)
	return chs
}

func sendDemo() {
	chs := [10]Channels{}
	for i := 0; i < 10; i++ {
		chs[i] = createWorker(i)
	}
	//channel取值是阻塞的
	for i, ch := range chs {
		ch.in <- 'a' + i
	}
	for i, ch := range chs {
		ch.in <- 'A' + i
	}
	for _, ch := range chs {
		<-ch.out
		<-ch.out
	}
}

func main() {
	sendDemo()
}
